home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 5 / QRZ Ham Radio Callsign Database - Volume 5.iso / unix / src / mkalist.c < prev    next >
C/C++ Source or Header  |  1993-11-01  |  1KB  |  92 lines

  1.  
  2.  
  3.  
  4. /*
  5. **    mkalist
  6. **
  7. **    Creates an unsorted index of the start of each call area in
  8. **      the database.
  9. **
  10. **    Copyright (c) 1993 by Fred Lloyd, AA7BQ
  11. **
  12. */
  13.  
  14. #include <stdio.h>
  15. #include <string.h>
  16. #include "cb.h"
  17.  
  18.  
  19. main(argc,argv)
  20. int argc;
  21. char *argv[];
  22. {
  23.     FILE *fp;
  24.     FILE *op;
  25.     long pos;
  26.     long start;
  27.     char    str[1024];
  28.     char    buf[40];
  29.     char    *p;
  30.     int    acount;
  31.     int    total;
  32.     char    area;
  33.  
  34.     if (!argv[1])
  35.     {
  36.         printf("Usage: %s dbase_name\n",argv[0]);
  37.         exit(1);
  38.     }
  39.     if ((fp=fopen(argv[1],"r")) == NULL)
  40.     {
  41.         printf("Error opening file %s.\n",argv[1]);
  42.         exit(1);
  43.     }
  44.     if ((op=fopen("alist.lst","w")) == NULL)
  45.     {
  46.         printf("Error opening nlist.ndx\n");
  47.         exit(1);
  48.     }
  49.     acount = 0;
  50.     total = 0;
  51.     area = '0';
  52.     start = 0;
  53.     printf("\n");
  54.     while (!feof(fp))
  55.     {
  56.         memset(str,0,sizeof(str));
  57.         pos = ftell(fp);
  58.         fgets(str,sizeof(str),fp);
  59.         if (!strlen(str))
  60.             break;
  61.         
  62.         p = strchr(str,',');
  63.         if (p)
  64.             *p = '\0';
  65.         else
  66.             continue;
  67.  
  68.         acount++;
  69.         if (p=strchr(str,area))
  70.             continue;
  71.  
  72.         printf("Area %c, start %ld, end %ld, total %d\n",area,
  73.             start, pos, acount);
  74.  
  75.         fprintf(op, "%c %ld %ld %d\n",area,start,pos,acount);
  76.  
  77.         area++;
  78.         total += acount;
  79.         acount = 0;
  80.         start = pos;
  81.     }
  82.     printf("Area %c, start %ld, end %ld, total %d\n",area,
  83.         start, pos, acount);
  84.  
  85.     fprintf(op, "%c %ld %ld %d\n",area,start,pos,acount);
  86.     printf("\nTotal: %d\n",total);
  87.     fclose(fp);
  88.     fclose(op);
  89.     exit(0);
  90. }
  91.  
  92.